package com.yjd.comm.base.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.yjd.comm.util.FrameUtil;
import com.yjd.comm.util.ServletUtil;
import com.yjd.comm.util.XssUtil;

/**
 * xss攻击处理拦截器*
 * 
 * @author ready
 * 
 */
public class XssInterceptor extends HandlerInterceptorAdapter {

	private static Logger logger = Logger.getLogger(XssInterceptor.class);

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		logger.debug("xss拦截器start");
		logger.debug("请求参数:"
				+ FrameUtil.json(ServletUtil.getParameterMap(request, true)));
		boolean valid = XssUtil.filterXss(request);
		logger.debug("请求参数(xss处理之后):"
				+ FrameUtil.json(ServletUtil.getParameterMap(request, true)));
		logger.debug("xss拦截器end");
		if (!valid) {
			FrameUtil.throwBaseException1("请求的参数有误!");
		}
		return true;
	}

}
